package com.aegean.MonitorExamSYS.examinee.action;

import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.examinee.business.ExamineeBusiness;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.aegean.MonitorExaxSYS.model.MonitorValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("ValidateUserExam")
@Scope("prototype")
public class ValidateUserExam extends ActionSupport implements
		ServletRequestAware {
	@Resource
	ExamineeBusiness business;
	private Date startTime;
	private Date endTime;
	private int exam_Id;
	private int status;
	private String msg;
	private boolean success;
	private HttpServletRequest request;
	private HttpSession session;

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public int getExam_Id() {
		return exam_Id;
	}

	public void setExam_Id(int exam_Id) {
		this.exam_Id = exam_Id;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		if (status == 0) {

			ExamineeValue one = (ExamineeValue) session
					.getAttribute("UserLogin");
			success = business.validationExam(exam_Id, startTime, endTime,
					one.getUser_Id());
			if (success == false) {
				msg = "对不起,您报考的考试与您已报过的考试时间重复,根据报考规则您不可以报考该考试！";
			} else {

			}
		} else {
			ExamineeValue one = (ExamineeValue) session
					.getAttribute("UserLogin");
			if (one == null) {
				success = false;
				msg = "对不起,您只有登录后才可以报名！";
				return SUCCESS;
			} else {
				success = business.validationExam(exam_Id, startTime, endTime,
						one.getUser_Id());
				if (success == false) {
					msg = "对不起,您报考的考试与您已报过的考试时间重复,根据报考规则您不可以报考该考试！";
				} else {

				}
			}
		}
		return SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;
		this.session = request.getSession();

	}
}
